package com.zmn.oms.services.impl.conf.workturn.bizmode;

import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.oms.model.entity.conf.workturn.bizmode.PlatBizMode;
import com.zmn.oms.model.entity.conf.workturn.bizmode.PlatBizModeQuery;
import com.zmn.oms.persistence.interfaces.conf.workturn.bizmode.PlatBizModeDao;
import com.zmn.oms.services.interfaces.conf.workturn.bizmode.PlatBizModeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PlatBizModelServiceImpl implements PlatBizModeService {

    @Resource
    private PlatBizModeDao platBizModeDao;

    @Override
    public PlatBizMode findByKey(Integer id) {
        return platBizModeDao.findByKey(id);
    }

    @Override
    public Integer findByPlat(Integer plat) {
        PlatBizModeQuery platBizModeQuery = new PlatBizModeQuery();
        platBizModeQuery.setPlat(plat);
        List<PlatBizMode> platBizModes = platBizModeDao.listByQuery(platBizModeQuery);
        if (CollectionUtil.isNotNullOrEmpty(platBizModes)) {
            Integer contractModel = platBizModes.get(0).getContractModel();
            return contractModel;
        }

        return null;
    }

    @Override
    public List<PlatBizMode> listPageByQuery(PlatBizModeQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return platBizModeDao.listPageByQuery(query);
    }

    @Override
    public List<PlatBizMode> listByQuery(PlatBizModeQuery query) {
        return platBizModeDao.listByQuery(query);
    }

    @Override
    public List<PlatBizMode> listAll() {
        return platBizModeDao.listAll();
    }

    @Override
    public Integer countByQuery(PlatBizModeQuery query) {
        return platBizModeDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(PlatBizMode platBizMode) {
        return platBizModeDao.updateByKey(platBizMode);
    }

    @Override
    public Integer insert(PlatBizMode platBizMode) {
        return platBizModeDao.insert(platBizMode);
    }

    @Override
    public Integer insertBatch(List<PlatBizMode> platBizModeList) {
        return platBizModeDao.insertBatch(platBizModeList);
    }

    @Override
    public Integer deleteByKey(Integer id) {
        return platBizModeDao.deleteByKey(id);
    }

    @Override
    public Integer deleteAllData() {
        return platBizModeDao.deleteAllData();
    }
}